package com.hjy.cloud.order.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hjy.cloud.order.config.UserFeignClient;
import com.hjy.cloud.order.entity.Order;
import com.hjy.cloud.order.service.OrderService;
import com.hjy.cloud.order.mapper.OrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import user.entity.User;

/**
* @author ASUS
* @description 针对表【tb_order】的数据库操作Service实现
* @createDate 2025-10-21 11:04:54
*/
@Slf4j
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order>
        implements OrderService{
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private UserFeignClient userFeignClient;

    //新需求：查询订单信息的时候，把对应用户信息查询出来
    @Override
    public Order findOrderByOrderId(Long orderId) {
        //步骤1：根据订单id查询订单信息
        Order order = orderMapper.selectOrderByOrderId(orderId);
        //步骤2：发起远程调用，查询用户信息
        //@LoadBalanced  //负载均衡 启用后，可以在服务调用时直接使用服务名：
        User user=userFeignClient.findUserById(order.getUserId());
        //步骤3：将用户信息设置到订单对象中
        order.setUser(user);
        //步骤4：返回订单信息
        return order;
    }

}